<?php
$id=intval($_POST['id']);
$url=$_POST['url'];
// XOA COMMENT DUA VAO ID
$mcom=new Model_Comment;
$mcom->query('select id,pid,reply,geturl from comment where id='.$id);
$row=$mcom->fetchOne();
if($row['reply']==0){
$mcom->delete_comment($id);
			
			if($row['pid']!=''){
				$mcom->query('select id from comment where pid='.$row['pid']);
				$num=$mcom->num_rows();
						if($num==0){
							$mcom->nonquery('update comment set reply=0 where id='.$row['pid']);
						}
			
			}
			
//- CHECK COMMENT DO CO 
}else{
$mcom->delete_comment($id);
//Neu no la comment cha, se xoa het comment reply con, co  pid  = id cua comment vua xoa
$mcom->nonquery("delete from comment where pid=".$id);
}

$cache=new cache;
$geturl=$row['geturl'];
switch($geturl){
	case "news":$cache->flush("news".$_POST['bv']); break;
	case "page":$cache->flush("page".$_POST['bv']); break;
	case "hoidap":
		$cache->flush("hoidap".$_POST['bv']);
		$db->connect();
		$db->query("select id from comment where number_id=".$_POST['id']." and geturl='hoidap'");
		$row=$db->num_rows();
		$db->nonquery("update hoidap set commentnum=".$row." where id=".$_POST['id']);
		$db->close();
		break;
}

